<?php

    function currency_sign() {

        if (isset($_GET['currency']))
            return $_GET['currency'];
        else
            return 'EUR';
    }

    function currency_convert($data) {

        if (isset($_GET['currency']) && $_GET['currency'] !== "EUR"):

            $keys = array('lowest_price', 'selling_total', 'price', 'selling_price');

            require_once EXTERNAL_URL . 'currency.php';
            $myCurrency = new currency(array('base' => 'EUR', 'foreign' => $_GET['currency']));
            $myCurrency->setKeys($keys);
            $data = $myCurrency->convert($data);
            $data['rate'] = $myCurrency->getRate();
            return $data;

        else:
            $data['rate'] = 1;
            return $data;
        endif;
    }

    function convert(&$data) {

        if (isset($_GET['currency']) && $_GET['currency'] !== "EUR"):

            $keys = array('lowest_price', 'selling_total', 'price', 'selling_price');

            require_once EXTERNAL_URL . 'currency.php';
            $myCurrency = new currency(array('base' => 'EUR', 'foreign' => $_GET['currency']));
            $myCurrency->setKeys($keys);
            $data = $myCurrency->convert($data);
            if (gettype($data) == 'array'):
                $data['rate'] = $myCurrency->getRate();
            endif;

        else:
            if (gettype($data) == 'array'):
                $data['rate'] = 1;
            endif;
        endif;
    }

    function fcu() {
        if (isset($_GET['currency']) && $_GET['currency'] !== "EUR")
            return "?currency=" . $_GET['currency'];
    }

    function lcu() {
        if (isset($_GET['currency']) && $_GET['currency'] !== "EUR")
            return "&currency=" . $_GET['currency'];
    }
    